#{extends 'main.html' /}
#{set title:'CoolSoft - Edit project configurations' /}
<meta http-equiv="expires" content="0">
<head>
<script type='text/javascript'>
    function CheckOther(){
        if (document.getElementById("selEffortUnits").value == "new") {
            document.getElementById("otherContainer").innerHTML = "<br /><input id='txtOther' type='text' class='validate[required,custom[onlyLetter]]' /> ";
            document.getElementById("txtOther").focus();
        }
        else 
            document.getElementById("otherContainer").innerHTML = "";
    }    
    function addUnit(){
        var form = document.getElementById("form");        
        var unitArg = document.createElement("input");
        unitArg.setAttribute("type", "hidden");
        unitArg.setAttribute("name", "effortUnit");
        if (document.getElementById("txtOther") != null) 
            unitArg.setAttribute("value", document.getElementById("txtOther").value);
        else 
            unitArg.setAttribute("value", document.getElementById("selEffortUnits").value);
        form.appendChild(unitArg);
	}
</script>
</head>
<h1><a href="@{Projects.showProject(project.getEntityId())}"><h2>${project.name}</h2></a></h1>
<h2>Edit project configurations</h2>
<hr/>
<br>
#{ifErrors} <h1 style="color:red">Oops...</h1>
#{/ifErrors}
#{form @Projects.editConf(project.getEntityId()), id:'form', onsubmit:'addUnit()'} 
	#{secure.check 'Edit project default sprint duration'}
		Default sprint duration:
		<br>
		<input type="text" name="defaultSprintDuration" value="${project.defaultSprintDuration}" class="validate[required,custom[onlyNumber]]" id="defaultSprintDuration" />
		<br>
	#{/secure.check}
	<br/>
	<br/>
<!-- As a scrum master I can edit the metric for effort estimation -->
	#{secure.check 'Set effort estimation metric'} 
		Effort estimation metric: 
		<br/>
		<div id="hiddenCtrls">
		    <input type="hidden" id="selectedUnit" name="selectedUnit" value="${selectedEffortUnit.unit}"><input type="hidden" id="projectId" name="projectId" value="${project.getEntityId()}">
		</div>
		<select id='selEffortUnits' name='selEffortUnits' onchange='CheckOther()'>
		    #{list items:distinctEffortUnits, as:'effortUnit'}<option value='${effortUnit.unit}'>${effortUnit.unit}</option>
		    #{/list}<option value='new'>Other</option>
		</select>
		<br/>
		<div id="otherContainer">
		</div>
	#{/secure.check}
<!-- End of Effort estimation change section -->
	<br/>
	<br/>
	<script>
	    $("#selEffortUnits").val($("#selectedUnit").val());
	    $("#form").attr("onsubmit", "addUnit()");
	</script>
	<input id="btnSave" type="submit" value="Save" />
#{/form} 